package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.AuthInfoDto;
import com.ewhale.feitengguest.view.user.mine.RNCertificationView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;
import com.simga.library.http.JsonUtil;
import com.simga.library.utils.CheckUtil;
import com.simga.library.utils.LogUtil;

import java.util.HashMap;
import java.util.Map;

public class RNCertificationPresenter extends IPresenter {
    public void loadAuthInfo() {
        mView.showProLoading();
        request(1, ApiHelper.USER_API.getAuthInfo(), null);
    }

    public void commitAuth(String name, String certificateNumber/**, String certificateFrontImg, String certificateBackImg, String handFrontImg, String handBacktImg*/) {
        mView.showProLoading();
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("certificateNumber", certificateNumber);
//        if(!CheckUtil.isNull(certificateFrontImg)){
//            params.put("certificateFrontImg", certificateFrontImg);
//        }
//        if(!CheckUtil.isNull(certificateBackImg)){
//            params.put("certificateBackImg", certificateBackImg);
//        }
//        if(!CheckUtil.isNull(handFrontImg)){
//            params.put("handFrontImg", handFrontImg);
//        }
//        if(!CheckUtil.isNull(handBacktImg)){
//            params.put("handBacktImg", handBacktImg);
//        }
        LogUtil.e("JIA","-----params : " + JsonUtil.toJson(params));
        request(2, ApiHelper.USER_API.commitAccountAuthMsg(params), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((RNCertificationView) mView).showAuthInfo((AuthInfoDto) result);
                break;
            case 2:
                ((RNCertificationView) mView).commitAuth();
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
